﻿using Demo_Excel列表框.Service;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo_Excel列表框.Model
{
    class ModelMainWindow : NotifyPropertyChange//逻辑
    {
        #region 建立单例

        private static ModelMainWindow uniqueInstance;

        private static readonly object locker = new object();

        public static ModelMainWindow GetInstance()
        {
            if (uniqueInstance == null)
            {
                lock (locker)
                {
                    if (uniqueInstance == null)
                    {
                        uniqueInstance = new ModelMainWindow();
                    }
                }
            }
            return uniqueInstance;
        }

        #endregion
       
        private ObservableCollection<CsSQLiteForList> _m_LG = new ObservableCollection<CsSQLiteForList>();
        public ObservableCollection<CsSQLiteForList> m_LG
        {
            get { return _m_LG; }
            set { if (_m_LG != value) { _m_LG = value; RaisePropertyChanged(""); } }
        }

        public void LGListSort()
        {
            for (int j = 0; j < m_LG.Count; j++)
            {
                m_LG[j].ID = (j + 1).ToString();
                m_LG.Add(m_LG[j]);
            }
            for (int j = 0; j < m_LG.Count; j++)
                m_LG.RemoveAt(0);
        }

        public void AddModel(string strId, string strName, string strDate, string strTime, string strReason)//添加数据
        {
            string modelId = (m_LG.Count + 1).ToString();
            string modelName = strName + "_" + strId;
            m_LG.Add(new CsSQLiteForList()
            {
                ID = modelId,
                Name = modelName,
                Date = strDate,
                Time = strTime,
                Type = "正常签卡",
                Reason = strReason
            });
        }


        //================//

        private ObservableCollection<CsSQLiteForList> _m_LG2 = new ObservableCollection<CsSQLiteForList>();
        public ObservableCollection<CsSQLiteForList> m_LG2
        {
            get { return _m_LG2; }
            set { if (_m_LG2 != value) { _m_LG2 = value; RaisePropertyChanged(""); } }
        }

        public void AddModel2(bool bRet, string strId, string strColor)//添加数据
        {
            string strOrdinal = (m_LG2.Count + 1).ToString();
            m_LG2.Add(new CsSQLiteForList()
            {
                FileIsChecked = bRet,
                FileOrdinal = strOrdinal,
                FileTime = strId,
                FileId = strId,
                FilePoint = strId,
                FileResult = strId,
                FileLineColor = strColor
            });
        }

        private void ReFreshList(ObservableCollection<CsSQLiteForList> _L)
        {
            int nListCount = _L.Count;
            for (int j = 0; j < nListCount; j++)
                _L.Add(_L[j]);
            for (int j = 0; j < nListCount; j++)
                _L.RemoveAt(0);
        }

        public void ChangeLineColors(int nIndex, int nColorNum)
        {
            switch (nColorNum)
            {
                case 1: m_LG2[nIndex].FileLineColor = "Red"; break;
                case 2: m_LG2[nIndex].FileLineColor = "Coral"; break;
                case 3: m_LG2[nIndex].FileLineColor = "Yellow"; break;
                case 4: m_LG2[nIndex].FileLineColor = "Lime"; break;
                case 5: m_LG2[nIndex].FileLineColor = "MediumSpringGreen"; break;
                case 6: m_LG2[nIndex].FileLineColor = "Blue"; break;
                case 7: m_LG2[nIndex].FileLineColor = "Fuchsia"; break;
                case 8: m_LG2[nIndex].FileLineColor = "Black"; break;
                default: break;
            }
            ReFreshList(m_LG2);

        }
    }
}
